<template>
  <div class="search">
    <input  type="text" class="frame" :placeholder="placeholder" :maxlength="maxlength" v-model="keyward" @input="search" >
  </div>
</template>

<script>

import getData from '@/service';
import { formatkeyward } from '@/lib/unit';
import {ref} from 'vue'
import { useStore } from 'vuex';
import { watch } from 'vue';
export default {
props:{
    placeholder:String,
    maxlength:Number,
},
setup(props){
    const keyward=ref('')
    const store=useStore()
    
    const search=()=>{
        const field=store.state.field
         if(keyward.value.length==props.maxlength){
            getData(field,formatkeyward(keyward.value))
         }
    }
    watch(
        ()=>store.state.field,
        ()=>{
            keyward.value=''
        }
        )
    return {
        keyward,
        search,
    }
}
}
</script>

<style lang="less" scoped>
    .search{
        position: fixed;
        top: .44rem;
        left: 0;
        width: 100%;
        z-index: 99;
        padding: .03rem .1rem;
        height: .38rem;
        background: #fff;
        box-sizing: border-box;
    }
    .frame{
        position: relative;
        height: 100%;
        width: 100%;
        font-size: .14rem;
        border: 1px solid #ddd;
        border-radius: .05rem;
        text-indent :0.1rem; 
        &:focus{
            border-color: #ed4040;
            box-shadow: 0 0 .02rem #ed4040;
            transition: all 0.3s;
        }
    }
</style>